package com.xgc.erp.order.purchase.service;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.xgc.common.base.service.BaseService;
import com.xgc.common.model.PurchaseOrder;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class PurchaseOrderService extends BaseService {
    private PurchaseOrder dao = new PurchaseOrder().dao();

    @Override
    public Model<?> getDao() {
        return this.dao;
    }

    /**
     * 批量修改订单状态
     * @param ids 待修改项
     * @param status 状态
     * @param modifier 修改人
     */
    public void modifyStatus(List<Integer> ids,String status,String modifier){
        List<Object> paramList = new ArrayList<>();
        paramList.add(status);
        paramList.add(modifier);
        paramList.add(new Date());
        StringBuilder sql= new StringBuilder("update "+getTable()+" set status = ? , modifier = ? , update_time = ? where "+getPK()+" in (");
        for(int i=0;i<ids.size();i++){
            sql.append("?");
            if(i<ids.size()-1){
                sql.append(",");
            }
            paramList.add(ids.get(i));
        }
        sql.append(")");
        Db.update(sql.toString(),paramList.toArray());
    }

}
